package co.edu.usbcali.egrapico.vista.ambient;

import co.edu.usbcali.egrapico.vista.tools.JPanelTranferHandlerContext;

public class PanelContext extends javax.swing.JInternalFrame implements java.io.Serializable {

    String nameParent;
    LPaneContext layeredPane;
    javax.swing.JScrollPane scroll1;
    private int program = 0;
    private int context = 0;
    private int ask = 0;
    private int tell = 0;
    private int msgS = 0;
    private int value = 0;
    private int variable = 0;
    private int argument = 0;
    private int Objs = 0;

    /**
     * Creates a new instance of PanelDragAndDrop
     */
    public PanelContext() {
        super("",//+(++openFrameCount) 
                true, //resizable
                true, //closable
                true, //maximizable
                true);//iconifiable
        scroll1 = new javax.swing.JScrollPane();
        scroll1.setAutoscrolls(true);
        layeredPane = new LPaneContext();
        scroll1.setViewportView(layeredPane);
        getContentPane().add(scroll1);
        setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        setTransferHandler(new JPanelTranferHandlerContext());
        setSize(300, 300);
        //Set the window's location.
        setLocation(40, 40);
        setVisible(true);

    }

    public void loadFrame(PanelContext ob) {
        layeredPane.setPreferredSize(ob.getLPane().getPreferredSize());
        layeredPane.setAreaLP(ob.getLPane().areaLPane());
        program = ob.program;
        variable = ob.variable;
        for (int i = 0; i < ob.getLPane().getComponentCount(); i++) {
            if (ob.getLPane().getComponent(i) instanceof LabelProgram) {
                LabelProgram label = new LabelProgram();
                label.setIcon(((LabelProgram) ob.getLPane().getComponent(i)).getIcon());
                label.setHorizontalTextPosition(javax.swing.JLabel.CENTER);
                label.setVerticalTextPosition(javax.swing.JLabel.BOTTOM);
                label.setText(((LabelProgram) ob.getLPane().getComponent(i)).getText());
                label.setLocation(((LabelProgram) ob.getLPane().getComponent(i)).getLocation());
                label.setSize(90, 90);
                label.setTextPane(((LabelProgram) ob.getLPane().getComponent(i)).getTextPane());
                label.setTextToolTip(((LabelProgram) ob.getLPane().getComponent(i)).getTextPane());
                label.setTitlePanel(((LabelProgram) ob.getLPane().getComponent(i)).getTitlePanel());
                label.setNameParent(((LabelProgram) ob.getLPane().getComponent(i)).getNameParent());
                layeredPane.addLabel(label);
                layeredPane.addLabeltoVector(label);
                label.Ladicionar();
            } else if (ob.getLPane().getComponent(i) instanceof LabelIdeOpe) {
                LabelIdeOpe label = new LabelIdeOpe();
                label.setIcon(((LabelIdeOpe) ob.getLPane().getComponent(i)).getIcon());
                label.setHorizontalTextPosition(javax.swing.JLabel.CENTER);
                label.setVerticalTextPosition(javax.swing.JLabel.BOTTOM);
                label.setText(((LabelIdeOpe) ob.getLPane().getComponent(i)).getText());
                label.setId(((LabelIdeOpe) ob.getLPane().getComponent(i)).getId());
                label.setLocation(((LabelIdeOpe) ob.getLPane().getComponent(i)).getLocation());
                label.setSize(90, 90);
                label.setTextPane(((LabelIdeOpe) ob.getLPane().getComponent(i)).getTextPane());
                label.setTextToolTip(((LabelIdeOpe) ob.getLPane().getComponent(i)).getTextPane());
                layeredPane.addLabel(label);
                layeredPane.addLabeltoVector(label);
            } else if (ob.getLPane().getComponent(i) instanceof LabelMethod) {
                LabelMethod label = new LabelMethod();
                label.setIcon(((LabelMethod) ob.getLPane().getComponent(i)).getIcon());
                label.setHorizontalTextPosition(javax.swing.JLabel.CENTER);
                label.setVerticalTextPosition(javax.swing.JLabel.BOTTOM);
                label.setText(((LabelMethod) ob.getLPane().getComponent(i)).getText());
                label.setLocation(((LabelMethod) ob.getLPane().getComponent(i)).getLocation());
                label.setSize(((LabelMethod) ob.getLPane().getComponent(i)).getSize());
                label.setTextPane(((LabelMethod) ob.getLPane().getComponent(i)).getTextPane());
                label.setTextToolTip(((LabelMethod) ob.getLPane().getComponent(i)).getTextPane());
                layeredPane.addLabel(label);
                layeredPane.addLabeltoVector(label);
            }
        }
        layeredPane.ApIcons(null);
    }

    public LPaneContext getLPane() {
        return layeredPane;
    }

    public void setNameParent(String name) {
        nameParent = name;
    }

    public int getPrograms() {
        return program;
    }

    public void addLayeredPane(LabelProgram label) {
        label.setNameParent(getTitle());
        if (label.getName().equals("Program")) {
            label.setName(label.getName() + (++program));
            label.setText(label.getName());
            label.setTextToolTip(label.getName() + ": ");
        }
        layeredPane.addLabel(label);
        layeredPane.addLabeltoVector(label);
        try {
            setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
    }

    public void addLayeredPane(LabelIdeOpe label) {
        if (label.getName().equals("Value")) {
            label.setName(label.getName() + (++value));
            label.setText(label.getName());
            label.setTextToolTip(label.getName() + ": ");
        } else if (label.getName().equals("Variable")) {
            label.setName(label.getName() + (++variable));
            label.setText(label.getName());
            label.setTextToolTip(label.getName() + ": ");
        } else if (label.getName().equals("Argument")) {
            label.setName(label.getName() + (++argument));
            label.setText(label.getName());
            label.setTextToolTip(label.getName() + ": ");
        }
        layeredPane.addLabel(label);
        layeredPane.addLabeltoVector(label);
        try {
            setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
    }

    public void addLayeredPane(LabelObject label) {
        label.setNameParent(getTitle());
        layeredPane.addLabel(label);
        layeredPane.addLabeltoVector(label);
        try {
            setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
    }

    public void addLayeredPane(LabelMethod label) {
        label.setNameParent(getTitle());
        label.setText(label.getName());
        layeredPane.addLabel(label);
        layeredPane.addLabeltoVector(label);
        try {
            setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
    }

    public void setUndoLPane() {
        layeredPane.Undo();
    }

    public void setRedoLPane() {
        layeredPane.Redo();
    }

    public int getRedosize() {
        return layeredPane.getRedoSize();
    }

    public int getUndosize() {
        return layeredPane.getUndoSize();
    }

    public void resProgram() {
        program--;
    }
}
